package com.dhecp.project.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.common.domain.ButtonState;
import com.dhecp.project.common.mapper.ButtonStateMapper;
import com.dhecp.project.common.service.ButtonStateService;

/**
 * 按钮状态 服务层
 * @author DH-Xxj
 * @version 2020年2月20日
 */
@Service
public class ButtonStateServiceImpl implements ButtonStateService {
    
    @Autowired
    private ButtonStateMapper buttonStateMapper;

	/**
	 * 查询用户按钮状态
	 * @param moduleTable
	 * @return List - ButtonState
	 * @author DH-Xxj
	 */
	@Override
	public List<ButtonState> queryButtonStateForUser(Map<String, Object> params) {
		params.put("agentuser", ShiroUtils.getUserId());
		params.put("mandator", ShiroUtils.getMandatorId());
		return buttonStateMapper.findButtonStateForUser(params);
	}

	/**
	 * 查询用户按钮状态
	 * @param moduleTable
	 * @return Map
	 * @author DH-Xxj
	 */
	@Override
	public Map<String, Object> getButtonStateObjectForUser(Map<String, Object> params) {
    	Map<String, Object> buttonStateMap = new HashMap<String, Object> ();
    	List<ButtonState> buttonStateList = queryButtonStateForUser(params);
    	for (ButtonState buttonState : buttonStateList){
    		if (ShiroUtils.getMandatorLevel() > 5 && "filedelete".equals(buttonState.getButName().toLowerCase()) && "disable".equals(buttonState.getButState().toLowerCase())){
    			buttonStateMap.put("filedelete", "enable");
    		}else{
        		buttonStateMap.put(buttonState.getButName().toLowerCase(), buttonState.getButState().toLowerCase());
    		}
    	}
    	return buttonStateMap;
	}

}
